package com.sky.service.impl;

import com.sky.result.Result;
import com.sky.service.ShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class ShopServiceImpl implements ShopService {
    //快捷键单词大小写切换，ctrl+shift+u
    private final static String key="SHOP_STATUS";
    @Autowired
    private StringRedisTemplate redisTemplate;
    /**
     * 设置当前店铺状态,其实就是写入数据到redis
     *
     * @param status
     * @return
     */
    @Override
    public Result setStatus(Integer status) {
        log.info("设置当前店铺状态为:{}",status);
        redisTemplate.opsForValue().set(key,status+"");
        return Result.success();
    }

    /**
     * 查询店铺状态
     * @return
     */
    @Override
    public Result getStatus() {
        log.info("查询店铺状态");
        String status = redisTemplate.opsForValue().get(key);
        return Result.success(Integer.parseInt(status));
    }
}